<template>
  <el-dialog
    :title="!dataForm.orderId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="100px">
    <el-form-item label="订单Id" prop="orderId">
      <el-input v-model="dataForm.orderId" placeholder="订单Id" disabled></el-input>
    </el-form-item>
      <el-form-item label="买家备注" prop="buyerRemake">
        <el-input v-model="dataForm.buyerRemake" placeholder="买家备注"></el-input>
      </el-form-item>
      <el-form-item label="订单地址" prop="orderAddress ">
        <el-input v-model="dataForm.orderAddress" placeholder="订单地址"></el-input>
      </el-form-item>
      <el-form-item label="订单会员号" prop="orderCardNumber ">
        <el-input v-model="dataForm.orderCardNumber " placeholder="订单会员号"></el-input>
      </el-form-item>
      <el-form-item label="订单用户" prop="orderMember">
        <el-input v-model="dataForm.orderMember" placeholder="订单用户"></el-input>
      </el-form-item>
      <el-form-item label="联系方式" prop="orderMobile">
        <el-input v-model="dataForm.orderMobile" placeholder="联系方式"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import {putObj} from '@/api/order/order'
  import {getObj} from '@/api/order/order'
  import {getAllShops} from '@/api/shop/shops'
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          userId:'',
          orderId: '',
          buyerRemake:'',
          orderAddress:'',
          orderCardNumber:'',
          orderMember:'',
          orderMobile:'',
          merList: [],
        },
        form:{
          merId:''
        },
        dataRule: {
          orderId: [
            { required: true, message: '订单Id不能为空', trigger: 'blur' }
          ],
          buyerRemake: [
            { required: true, message: '买家备注不能为空', trigger: 'blur' }
          ],
          orderAddress: [
            { required: true, message: '订单地址不能为空', trigger: 'blur' }
          ],
          orderCardNumber: [
            { required: true, message: '订单会员号不能为空', trigger: 'blur' }
          ],
          orderMember: [
            { required: true, message: '订单用户不能为空', trigger: 'blur' }
          ],
          orderMobile: [
            { required: true, message: '联系方式不能为空', trigger: 'blur' }
          ],
        }
      }
    },
    mounted(){

    },
    methods: {
      init (id) {
        this.dataForm.orderId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.orderId) {
            const data = new FormData()
            data.append('orderId',this.dataForm.orderId)
            getObj(data).then(res => {
              this.dataForm = res.data.order
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit(){
        const params = new FormData()
        params.append('orderId',this.dataForm.orderId)
        params.append('buyerRemake',this.dataForm.buyerRemake)
        params.append('orderAddress',this.dataForm.orderAddress)
        params.append('orderCardNumber',this.dataForm.orderCardNumber)
        params.append('orderMember',this.dataForm.orderMember)
        params.append('orderMobile',this.dataForm.orderMobile)
        putObj(params).then(res =>{
          if(res.data.code === 0){
            this.$message({
              message: '更新成功',
              type: 'success',
            })
            this.visible = false
            this.$emit('refreshDataList')
          }
        })
      },
    }
  }
</script>
